unit AppSettingForm;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls ,uTaoBaoManager, uTaoBaoPublic;

type
  TfrmAppSetting = class(TForm)
    lblAppKey: TLabel;
    edtAppKey: TEdit;
    lblAppSecret: TLabel;
    edtAppSecret: TEdit;
    lblCallBackUrl: TLabel;
    edtCallBackUrl: TEdit;
    btnOK: TButton;
    btnCancel: TButton;
    cmbEnvrion: TComboBox;
    lblEnvrion: TLabel;
    procedure btnOKClick(Sender: TObject);
    procedure FormCreate(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  frmAppSetting: TfrmAppSetting;

implementation

{$R *.dfm}

procedure TfrmAppSetting.btnOKClick(Sender: TObject);
var
  APIUrl:String;
  SessionUrl:String;
begin
  case Self.cmbEnvrion.ItemIndex of
    0:
    begin
      APIUrl:=CONST_SANDBOX_APIURL;
      SessionUrl:=CONST_SANDBOX_SESSIONURL;
    end;
    1:
    begin
      APIUrl:=CONST_OFFICIAL_APIURL;
      SessionUrl:=CONST_OFFICIAL_SESSIONURL;
    end;
  end;

  GlobalTaoBaoManager.Auth.AppKey:=Self.edtAppKey.Text;
  GlobalTaoBaoManager.Auth.AppSecret:=Self.edtAppSecret.Text;
  GlobalTaoBaoManager.Auth.CallBackUrl:=Self.edtCallBackUrl.Text;
  GlobalTaoBaoManager.Auth.SessionUrl:=SessionUrl;
  GlobalTaoBaoManager.Auth.APIUrl:=APIUrl;

  GlobalTaoBaoManager.Auth.SaveToXmlFile('AppSetting.xml');

end;

procedure TfrmAppSetting.FormCreate(Sender: TObject);
begin
  Self.edtAppKey.Text:=GlobalTaoBaoManager.Auth.AppKey;
  Self.edtAppSecret.Text:=GlobalTaoBaoManager.Auth.AppSecret;
  Self.edtCallBackUrl.Text:=GlobalTaoBaoManager.Auth.CallBackUrl;
  Self.cmbEnvrion.ItemIndex:=0;
  if CONST_OFFICIAL_APIURL=GlobalTaoBaoManager.Auth.APIUrl then
  begin
    Self.cmbEnvrion.ItemIndex:=1;
  end;

end;

end.
